home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-3485 / art-5570 / atsis.lst < prev    next >
File List  |  1994-08-10  |  8KB  |  229 lines

  1. ' **** Atari SIS program v2.0 ****
  2. '   routine from the SIRDS FAQ
  3. '
  4. ' read *.red (raw) file into thedepth array
  5. ' read *.tga file into tile array
  6. ' write *.tga file out of thesird array
  7. '
  8. bkdepth%=-800             ! depth of background in pixels
  9. e%=180                    ! eye separation in pixels
  10. o%=700                    ! observer-screen distance in pixels
  11. oversam%=6                ! oversampling ratio -- can be 1, 2, 4, 6
  12. dohiddenrem!=FALSE        ! enable/disable SLOW hidden point removal
  13. xres%=640                 ! width of the picture in pixels
  14. yres%=470                 ! height of picture in pixels
  15. txr%=96                   ! width of tile in pixels
  16. tyr%=72                   ! height of tile in pixels
  17. '
  18. DIM thedepth|(xres%*yres%)
  19. depthofs%=VARPTR(thedepth|(0))
  20. DIM link%(xres%*oversam%)
  21. DIM pixels|(xres%*oversam%*3)
  22. DIM z%(xres%)
  23. DIM pal|(3*numcolors%)
  24. DIM thesird|(xres%*(yres%+10)*3)       ! add 10 "help lines"
  25. sirdofs%=VARPTR(thesird|(0))
  26. DIM tile|(txr%*tyr%*3)
  27. tileofs%=VARPTR(tile|(0))
  28. '
  29. FILESELECT "\*.red","",dep$
  30. IF dep$=""
  31.   END
  32. ENDIF
  33. PRINT "Input RAW depth file: ";dep$
  34. OPEN "i",#1,dep$
  35. BGET #1,depthofs%,xres%*yres%
  36. CLOSE #1
  37. '
  38. FILESELECT "\*.tga","",til$
  39. IF til$=""
  40.   END
  41. ENDIF
  42. PRINT "Input TGA tile file: ";til$
  43. OPEN "i",#1,til$
  44. SEEK #1,18
  45. BGET #1,tileofs%,txr%*tyr%*3
  46. CLOSE #1
  47. '
  48. PRINT "Res. ";xres%;"x";yres%;", ";
  49. IF oversam%=1
  50.   PRINT "no oversampling";
  51. ELSE
  52.   PRINT oversam%;" times oversampling";
  53. ENDIF
  54. IF dohiddenrem!
  55.   PRINT ", hidden point removal."
  56. ELSE
  57.   PRINT "."
  58. ENDIF
  59. init_sirds
  60. do_sirds
  61. PRINT CHR$(7);
  62. '
  63. FILESELECT "\*.tga","",sir$
  64. IF sir$=""
  65.   END
  66. ENDIF
  67. PRINT "Output TGA SIRDS file: ";sir$
  68. OPEN "o",#1,sir$
  69. PRINT #1;CHR$(0);CHR$(0);CHR$(2);
  70. PRINT #1;CHR$(0);CHR$(0);CHR$(0);CHR$(0);CHR$(0);
  71. PRINT #1;CHR$(0);CHR$(0);CHR$(0);CHR$(0);
  72. PRINT #1;CHR$(xres% MOD 256);CHR$(xres% DIV 256);
  73. PRINT #1;CHR$((yres%+10) MOD 256);CHR$((yres%+10) DIV 256);
  74. PRINT #1;CHR$(24);CHR$(32);
  75. BPUT #1,sirdofs%,xres%*(yres%+10)*3
  76. CLOSE #1
  77. END
  78. '
  79. '
  80. '
  81. PROCEDURE init_sirds
  82.   ' add "help lines"
  83.   LOCAL x%,y%,helpdist,th%
  84.   helpdist=ABS(bkdepth%)*e%/(2*(ABS(bkdepth%)+o%))
  85.   th%=0
  86.   FOR y%=9 DOWNTO 0
  87.     FOR x%=xres%/2-helpdist-th% TO xres%/2-helpdist+th%
  88.       thesird|(3*(y%*xres%+x%))=255        ! blue
  89.       thesird|(3*(y%*xres%+x%)+1)=255      ! green
  90.       thesird|(3*(y%*xres%+x%)+2)=255      ! red
  91.     NEXT x%
  92.     FOR x%=xres%/2+helpdist-th% TO xres%/2+helpdist+th%
  93.       thesird|(3*(y%*xres%+x%))=255
  94.       thesird|(3*(y%*xres%+x%)+1)=255
  95.       thesird|(3*(y%*xres%+x%)+2)=255
  96.     NEXT x%
  97.     INC th%
  98.   NEXT y%
  99. RETURN
  100. '
  101. PROCEDURE do_sirds
  102.   ' render the SIRDS
  103.   LOCAL x%,y%,h%,u%,dx%,xx%,highest%,separation%,left%,right%,pp%,tilep%,r%,g%,b%,v,visible!
  104.   FOR y%=0 TO yres%-1
  105.     PRINT AT(1,4);"Rendering line ";y%+1;" of ";yres%
  106.     FOR x%=0 TO xres%*oversam%-1
  107.       link%(x%)=x%
  108.     NEXT x%
  109.     highest%=bkdepth%
  110.     FOR x%=0 TO xres%-1
  111.       ' h%=bkdepth%+128+63*(SIN(x%/70*PI)+COS(y%/70*PI))
  112.       h%=bkdepth%+thedepth|(y%*xres%+x%)
  113.       z%(x%)=h%
  114.       IF h%>highest%
  115.         highest%=h%
  116.       ENDIF
  117.     NEXT x%
  118.     FOR x%=0 TO xres%*oversam%-1
  119.       separation%=(e%*oversam%*z%(x%/oversam%))/(z%(x%/oversam%)-o%)
  120.       left%=x%-separation%/2
  121.       right%=left%+separation%
  122.       IF (left%>=0) AND (right%<xres%*oversam%)
  123.         visible!=TRUE
  124.         IF dohiddenrem!
  125.           v=2*(o%-z%(x%/oversam%))/e%
  126.           dx%=1
  127.           REPEAT
  128.             u%=z%(x%/oversam%)+dx%*v
  129.             IF (z%((x%+dx%)/oversam%)>=u%) OR (z%((x%-dx%)/oversam%)>=u%)
  130.               visible!=FALSE
  131.             ENDIF
  132.             INC dx%
  133.           UNTIL (u%>highest%) OR (NOT visible!)
  134.         ENDIF
  135.         IF visible!
  136.           link%(right%)=left%
  137.         ENDIF
  138.       ENDIF
  139.     NEXT x%
  140.     FOR x%=0 TO xres%*oversam%-1
  141.       tilep%=(y% MOD tyr%)*txr%+(x% DIV oversam%) MOD txr%
  142.       IF link%(x%)=x%
  143.         pixels|(3*x%)=tile|(3*tilep%)
  144.         pixels|(3*x%+1)=tile|(3*tilep%+1)
  145.         pixels|(3*x%+2)=tile|(3*tilep%+2)
  146.       ELSE
  147.         pixels|(3*x%)=pixels|(3*link%(x%))
  148.         pixels|(3*x%+1)=pixels|(3*link%(x%)+1)
  149.         pixels|(3*x%+2)=pixels|(3*link%(x%)+2)
  150.       ENDIF
  151.     NEXT x%
  152.     FOR x%=0 TO xres%-1
  153.       xx%=x%*oversam%
  154.       SELECT oversam%
  155.       CASE 1
  156.         b%=pixels|(3*xx%)
  157.         g%=pixels|(3*xx%+1)
  158.         r%=pixels|(3*xx%+2)
  159.       CASE 2
  160.         IF (x%>0) AND (x%<xres%-1)
  161.           b%=pixels|(3*xx%)*42+(pixels|(3*(xx%-1))+pixels|(3*(xx%+1)))*24
  162.           b%=b%+(pixels|(3*(xx%-2))+pixels|(3*(xx%+2)))*5
  163.           b%=b%/100
  164.           g%=pixels|(3*xx%+1)*42+(pixels|(3*(xx%-1)+1)+pixels|(3*(xx%+1)+1))*24
  165.           g%=g%+(pixels|(3*(xx%-2)+1)+pixels|(3*(xx%+2)+1))*5
  166.           g%=g%/100
  167.           r%=pixels|(3*xx%+2)*42+(pixels|(3*(xx%-1)+2)+pixels|(3*(xx%+1)+2))*24
  168.           r%=r%+(pixels|(3*(xx%-2)+2)+pixels|(3*(xx%+2)+2))*5
  169.           r%=r%/100
  170.         ELSE
  171.           b%=pixels|(3*xx%)
  172.           g%=pixels|(3*xx%+1)
  173.           r%=pixels|(3*xx%+2)
  174.         ENDIF
  175.       CASE 4
  176.         IF (x%>0) AND (x%<xres%-1)
  177.           b%=pixels|(3*xx%)*26+(pixels|(3*(xx%-1))+pixels|(3*(xx%+1)))*18
  178.           b%=b%+(pixels|(3*(xx%-2))+pixels|(3*(xx%+2)))*12
  179.           b%=b%+(pixels|(3*(xx%-3))+pixels|(3*(xx%+3)))*7
  180.           b%=b%/100
  181.           g%=pixels|(3*xx%+1)*26+(pixels|(3*(xx%-1)+1)+pixels|(3*(xx%+1)+1))*18
  182.           g%=g%+(pixels|(3*(xx%-2)+1)+pixels|(3*(xx%+2)+1))*12
  183.           g%=g%+(pixels|(3*(xx%-3)+1)+pixels|(3*(xx%+3)+1))*7
  184.           g%=g%/100
  185.           r%=pixels|(3*xx%+2)*26+(pixels|(3*(xx%-1)+2)+pixels|(3*(xx%+1)+2))*18
  186.           r%=r%+(pixels|(3*(xx%-2)+2)+pixels|(3*(xx%+2)+2))*12
  187.           r%=r%+(pixels|(3*(xx%-3)+2)+pixels|(3*(xx%+3)+2))*7
  188.           r%=r%/100
  189.         ELSE
  190.           b%=pixels|(3*xx%)
  191.           g%=pixels|(3*xx%+1)
  192.           r%=pixels|(3*xx%+2)
  193.         ENDIF
  194.       CASE 6
  195.         IF (x%>0) AND (x%<xres%-1)
  196.           b%=pixels|(3*xx%)*14+(pixels|(3*(xx%-1))+pixels|(3*(xx%+1)))*14
  197.           b%=b%+(pixels|(3*(xx%-2))+pixels|(3*(xx%+2)))*11
  198.           b%=b%+(pixels|(3*(xx%-3))+pixels|(3*(xx%+3)))*8
  199.           b%=b%+(pixels|(3*(xx%-4))+pixels|(3*(xx%+4)))*5
  200.           b%=b%+(pixels|(3*(xx%-5))+pixels|(3*(xx%+5)))*3
  201.           b%=b%+(pixels|(3*(xx%-6))+pixels|(3*(xx%+6)))*2
  202.           b%=b%/100
  203.           g%=pixels|(3*xx%+1)*14+(pixels|(3*(xx%-1)+1)+pixels|(3*(xx%+1)+1))*14
  204.           g%=g%+(pixels|(3*(xx%-2)+1)+pixels|(3*(xx%+2)+1))*11
  205.           g%=g%+(pixels|(3*(xx%-3)+1)+pixels|(3*(xx%+3)+1))*8
  206.           g%=g%+(pixels|(3*(xx%-4)+1)+pixels|(3*(xx%+4)+1))*5
  207.           g%=g%+(pixels|(3*(xx%-5)+1)+pixels|(3*(xx%+5)+1))*3
  208.           g%=g%+(pixels|(3*(xx%-6)+1)+pixels|(3*(xx%+6)+1))*2
  209.           g%=g%/100
  210.           r%=pixels|(3*xx%+2)*14+(pixels|(3*(xx%-1)+2)+pixels|(3*(xx%+1)+2))*14
  211.           r%=r%+(pixels|(3*(xx%-2)+2)+pixels|(3*(xx%+2)+2))*11
  212.           r%=r%+(pixels|(3*(xx%-3)+2)+pixels|(3*(xx%+3)+2))*8
  213.           r%=r%+(pixels|(3*(xx%-4)+2)+pixels|(3*(xx%+4)+2))*5
  214.           r%=r%+(pixels|(3*(xx%-5)+2)+pixels|(3*(xx%+5)+2))*3
  215.           r%=r%+(pixels|(3*(xx%-6)+2)+pixels|(3*(xx%+6)+2))*2
  216.           r%=r%/100
  217.         ELSE
  218.           b%=pixels|(3*xx%)
  219.           g%=pixels|(3*xx%+1)
  220.           r%=pixels|(3*xx%+2)
  221.         ENDIF
  222.       ENDSELECT
  223.       thesird|(3*((y%+10)*xres%+x%))=b%    ! blue
  224.       thesird|(3*((y%+10)*xres%+x%)+1)=g%  ! green
  225.       thesird|(3*((y%+10)*xres%+x%)+2)=r%  ! red
  226.     NEXT x%
  227.   NEXT y%
  228. RETURN
  229.